#include "EndConnectInsDestHandlerB.h"
#include "OriBodyRecvRelayHandler.h"
#include "EndInsDestSendHandlerB.h"
#include "GlobalContext.h"

using namespace log4cplus;

Logger EndConnectInsDestHandlerB::log=GetLogger(LOG4CPLUS_TEXT("EndConnectInsDestHandlerB"));

ITransHandler* EndConnectInsDestHandlerB::GetNextHandler()
{
	return new EndInsDestSendHandlerB(m_oriRecvCount);
}

ITransHandler::ExecuteResultCode EndConnectInsDestHandlerB::OnExecuteError(ClientContext &client,OVERLAPPED *ovl,ITransHandler::ExecuteResultCode executeResult)
{
	delete client.SetCurrentHandler(new OriBodyRecvRelayHandler());
	client.FreeInsteadContext();
	LOG4CPLUS_DEBUG_STR(log,LOG4CPLUS_TEXT("In EndConnB,try to send instead server's request data  failed(free instead context),try to retranslate original server receive data."));
	::PostQueuedCompletionStatus(GlobalContext::Instance().IOCP(),m_oriRecvCount,static_cast<ULONG_PTR>(client.SequenceNo()),client.OVL());
	return ITransHandler::ExecuteOK;
}